/**
 * jims
 */
package com.jims.api.v1.controller.patient;


import com.jims.master.common.data.Message;
import com.jims.master.common.utils.SecurityUtil;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.patient.RecordUpload.entity.RecordUpload;
import com.jims.master.modules.patient.RecordUpload.service.RecordUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 病历报告表Controller
 * @author jct
 * @version 2017-12-08
 */
@RestController
@RequestMapping(value = "recordUpload")
public class RecordUploadController extends BaseController {

	@Autowired
	private RecordUploadService recordUploadService;

	 /**
	   * @Title:
	   * @Description: （上传病历）
	   * @param idcard 身份证号
	   * @param imgUrl 图片地址
	   * @param medicalType 上传类型
	   * @param describe 描述
	   * @param visitDate 检查日期
	   * @param orgName 机构名称
	   * @return
	   * @author jict
	   * @date 2017/12/13
	   * @throws
	  */
	@RequestMapping(value = "V100/recordUpload", method = {RequestMethod.GET, RequestMethod.POST})
	public String recordUpload(@RequestParam(required = true) String idcard, String imgUrl, String medicalType, String describe,@RequestParam(required = true)  String visitDate, String orgName) {
		Message msa = new Message();
		RecordUpload recordUpload =new RecordUpload();
		recordUpload.setIdcard(idcard);
		recordUpload.setDescribe(describe);
		recordUpload.setImgUrl(imgUrl);
		recordUpload.setMedicalType(medicalType);
		recordUpload.setOrgName(orgName);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long lt = new Long(visitDate);
		Date date = new Date(lt);
		simpleDateFormat.format(date);
		recordUpload.setVisitDate(date);
		int result = recordUploadService.save(recordUpload);
		if (result == 1) {
			msa.setData("上传成功");
		}else{
			msa.setData("上传失败");
		}
		return SecurityUtil.encryptMsgData(msa);
	}

	/**
	 * @Title:
	 * @Description: （获取上传病历详情）
	 * @param id 身份证号
	 * @return
	 * @author jict
	 * @date 2017/12/28
	 * @throws
	 */
	@RequestMapping(value = "V100/getRecordUpload", method = {RequestMethod.GET, RequestMethod.POST})
	public String getRecordUpload(@RequestParam(required = true) String id) {
		Message msa = new Message();
		RecordUpload recordUpload =recordUploadService.get(id);
		msa.setData(recordUpload);
		return SecurityUtil.encryptMsgData(msa);
	}

	/**
	 * @Title:
	 * @Description: （删除上传病历）
	 * @param id
	 * @return
	 * @author jict
	 * @date 2017/12/28
	 * @throws
	 */
	@RequestMapping(value = "V100/deleteRecordUpload", method = {RequestMethod.GET, RequestMethod.POST})
	public String deleteRecordUpload(@RequestParam(required = true) String id) {
		Message msa = new Message();
		RecordUpload recordUpload = recordUploadService.get(id);
		int i = recordUploadService.delete(recordUpload);
		if (i > 0 ) {
			msa.setData("删除成功");
			return SecurityUtil.encryptMsgData(msa);
		}else{
			msa.setData("删除失败");
			return SecurityUtil.encryptMsgData(msa);
		}
	}

}